import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  const isLogin = localStorage.ele_login ? true : false;
  if (to.path === '/login') {
    // 如果已经登录过，就直接跳转首页
    isLogin ? next('/') : next()
  } else {
    isLogin ? next() : next('/login')
  }
})

export default router
